package LeetCode.month01.day12;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class No763 {
    public static void main(String[] args) {
        String s = "ababcbacadefegdehijhklij";
        System.out.println(partitionLabels(s));
    }

    public static List<Integer> partitionLabels(String s) {
        List<Integer> list = new ArrayList<>();
        int len = 0;
        while(len<s.length()){
            char c = s.charAt(len);
            int num = s.lastIndexOf(c);
            for (int i = len+1; i <=num; i++) {
                char c1 = s.charAt(i);
                if(s.lastIndexOf(c1)>num) num = s.lastIndexOf(c1);
            }
            list.add(num-len+1);
            len = num+1;
        }
        return list;
    }
}
